package edu.bit.water.controller;

import edu.bit.water.entity.*;
import edu.bit.water.service.WaterSavingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/water_saving")
public class WaterSavingController {

    @Autowired
    private WaterSavingService waterSavingService;

    /**
     * 查询WATER_SAVING中的记录
     * @return WATER_SAVING中的相应记录
     */
    @RequestMapping("/select")
    @ResponseBody
    public Map<String, Object> select(String evaBasis){
        Map<String, Object> modelMap = new HashMap<>();
        List<WaterSaving> list = waterSavingService.select(evaBasis);
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }

    /**
     * 查询META_MANAGEMENT_INDICATOR中的记录
     * @return META_MANAGEMENT_INDICATOR中的相应记录
     */
    @RequestMapping("/get_management_indicator_data")
    @ResponseBody
    public Map<String, Object> getManagementIndicatorData(String standardNum){
        Map<String, Object> modelMap = new HashMap<>();
        List<MetaManagementIndicator> list = waterSavingService.getManagementIndicatorData(standardNum);
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }

    /**
     * @param managementIndicator
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/insert_management_indicator_data")
    @ResponseBody
    public Map<String, String> insertManagementIndicatorData(ManagementIndicator managementIndicator){
        return waterSavingService.insertManagementIndicatorData(managementIndicator);
    }

    /**
     * 查询META_TECHNICAL_INDICATOR中的记录
     * @return META_TECHNICAL_INDICATOR中的相应记录
     */
    @RequestMapping("/get_technical_indicator_data")
    @ResponseBody
    public Map<String, Object> getTechnicalIndicatorData(String standardNum){
        Map<String, Object> modelMap = new HashMap<>();
        List<MetaTI> list = waterSavingService.getTechnicalIndicatorData(standardNum);
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }

    /**
     * @param technicalIndicator
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/insert_technical_indicator_data")
    @ResponseBody
    public Map<String, String> insertTechnicalIndicatorData(TechnicalIndicator technicalIndicator){
        return waterSavingService.insertTechnicalIndicatorData(technicalIndicator);
    }
}
